﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.EnterpriseServices;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JobbJakt;

namespace JobbJaktWeb
{
    public partial class PersonInformationWebForm : System.Web.UI.Page
    {
        private DateTime date;


        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                var user = Users.PrintUser(Session["UserName"].ToString());               
                PrintUserDetails(user);
            }
            
        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            string UserName = Session["UserName"].ToString();
            DateTime datum = Users.GetRegistrationDate(UserName);
            date = datum;

            bool license;
            if (RadioButtonListDriversLicense.SelectedIndex==0)
            {
                license = true;
            }
            else
            {
                license = false;
            }

            Users user = new Users
            {
                UserName = Session["UserName"].ToString(),
                Authorization = (Authorization)Session["Authorization"],//???????????????????????????
                Password = EncryptionClass.DecryptString(Session["Password"].ToString()),
                SocialSecurityNumber = TextBoxSocialSecurityNumber.Text.Trim(),
                FirstName = TextBoxFirstName.Text.Trim(),
                LastName = TextBoxLastName.Text.Trim(),
                Address = TextBoxAddress.Text.Trim(),
                ZipCode = TextBoxZipCode.Text.Trim(),
                City = TextBoxCity.Text.Trim(),
                Phone = TextBoxPhoneNumber.Text.Trim(),
                Email = TextBoxEmail.Text.Trim(),
                Interest = TextBoxInterests.Text.Trim(),
                Attributes = TextBoxAttributes.Text.Trim(),
                DriversLicense = license,
                RegistrationDate = date,
                Photo="nophoto",
                Active=true
            };
           int test = Users.UpdateUser(user);

           LabelConfirm.Visible = true;
        }

        private void PrintUserDetails(Users users)
        {
            users = Users.PrintUser(Session["UserName"].ToString());

            var user = new Users();          
            TextBoxSocialSecurityNumber.Text = users.SocialSecurityNumber;
            TextBoxFirstName.Text = users.FirstName;
            TextBoxLastName.Text = users.LastName;
            TextBoxAddress.Text = users.Address;
            TextBoxZipCode.Text = users.ZipCode;
            TextBoxCity.Text = users.City;
            TextBoxPhoneNumber.Text = users.Phone;
            TextBoxEmail.Text = users.Email;
            TextBoxInterests.Text = users.Interest;
            TextBoxAttributes.Text = users.Attributes;
            date = users.RegistrationDate;
            //Photo
            if (user.DriversLicense == true)
            {
                RadioButtonListDriversLicense.SelectedIndex = 0;
            }
            else
            {
                RadioButtonListDriversLicense.SelectedIndex = 1;
            }
            
        }
    }
}